package com.nstc.sftpExchange.common;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
public class RestResponse<T> implements Serializable {

    private static final long serialVersionUID = -510660846888117779L;
    protected static final String SUCCESS_MSG = "success";
    protected static final String FAILURE_MSG = "failure, unknown error ";
    protected static final String NO_AUTH_MSG = "sorry, current login No authority for some request";
    protected static final String TIMEOUT_MSG = "this request time-out, include network error and server time-out ";
    protected static final String SERVER_ERROR_MSG = "server error ";
    protected Integer code;
    protected String msg;
    protected T data;

    public RestResponse() {
    }

    public RestResponse(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> RestResponse<T> newEntity() {
        return new RestResponse<>();
    }

    public static <T> RestResponse<T> newEntity(int ret, String msg, T object) {
        return new RestResponse<>(ret, msg, object);
    }

    public static <T> RestResponse<T> success(T object) {
        return new RestResponse<>(200, "success", object);
    }

    public static <T> RestResponse<T> success(String msg, T object) {
        return new RestResponse<>(200, msg, object);
    }

    public static <T> RestResponse<T> failure(T object) {
        return new RestResponse(-1, "failure, unknown error ", object);
    }

    public static <T> RestResponse<T> failure(String msg, T object) {
        return new RestResponse<>(-1, msg, object);
    }

    public static <T> RestResponse<T> noAuth(T object) {
        return new RestResponse<>(-800, "sorry, current login No authority for some request", object);
    }

    public static <T> RestResponse<T> noAuth(String msg, T object) {
        return new RestResponse<>(-800, msg, object);
    }

    public static <T> RestResponse<T> timeout(T object) {
        return new RestResponse<>(-101, "this request time-out, include network error and server time-out ", object);
    }

    public static <T> RestResponse<T> timeout(String msg, T object) {
        return new RestResponse<>(-101, msg, object);
    }

    public static <T> RestResponse<T> serverErr(T object) {
        return new RestResponse<>(-500, "server error ", object);
    }

    public static <T> RestResponse<T> serverErr(String msg, T object) {
        return new RestResponse<>(-500, msg, object);
    }
}
